package com.homegoods.classify.ui.fragment;

import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.util.Log;
import android.view.View;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.alibaba.fastjson.JSON;
import com.homegoods.aroutercomment.ARouterPath;
import com.homegoods.classify.R;
import com.homegoods.classify.adapter.ZPOtherAdapter;
import com.homegoods.classify.databinding.ClassifyFragmentOtherBinding;
import com.homegoods.classify.model.ClassifyModel;
import com.homegoods.classify.persenter.ZPOtherPresenter;
import com.kedll.library.fragment.KBaseFragment;
import com.kedll.library.util.ToastUtil;

/**
 * add shibo.zheng
 * 19/06/20
 * 其他分类 fragment
 */
@Route(path = ARouterPath.PATH_ZP_CLASSIFY_OTHER)
public class ZPClassifyOtherFragment extends KBaseFragment<ClassifyFragmentOtherBinding, ZPOtherPresenter> {
    @Autowired(name = "classifyModel")
    public ClassifyModel.ProductGroupListBean classifyModel;

    @Override
    protected void initEvent(Bundle savedInstanceState) {
        ARouter.getInstance().inject(this);
        Log.d(TAG, "initEvent: classifyModel ZPClassifyOtherFragment == " + JSON.toJSONString(classifyModel));
        mBinding.otherRightList.setLayoutManager(new GridLayoutManager(getContext(), 3));
        ZPOtherAdapter adapter = new ZPOtherAdapter(getContext(), classifyModel.getSubList());
        mBinding.otherRightList.setAdapter(adapter);
        adapter.setMyItemClick(new ZPOtherAdapter.MyItemClick() {
            @Override
            public void MyItemClick(View view, int postion) {
//                ToastUtil.showToast(classifyModel.getSubList().get(postion).getGroupName() +"  "+ classifyModel.getSubList().get(postion).getId());
                int id = classifyModel.getSubList().get(postion).getId();
                ARouter.getInstance().build(ARouterPath.PATH_SEARCH_RESULT).withString("searchId", String.valueOf(id)).navigation();
            }
        });
    }

    @Override
    protected ZPOtherPresenter getPresenter() {
        return new ZPOtherPresenter(this);
    }

    @Override
    protected int getLayout() {
        return R.layout.classify_fragment_other;
    }
}
